<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* new Promise((resolve,reject)=>{
            setTimeout(() => {
                reject('NavigationDuplicated: Avoided redundant navigation to current location: "/search".')
            }, 2000);
        }) */

        function push(location, onComplete, onAbort) {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    reject(
                        'NavigationDuplicated: Avoided redundant navigation to current location: "/search".')
                }, 2000);
            })
            .then(onComplete)
            . catch(onAbort)
        }

        //onComplete和onAbort是1两个回调函数,当供promise来处理失败还是成功时调用,如果不给onComplete和onAbort传值,拿就没有处理实例的函数,会默认穿透,就会有之前传入的失败的值,有回调函数处理后就会按照回调函数执行
        function myPush (a,onComplete=()=>{},onAbort=()=>{}){
            return push(a,onComplete,onAbort)
        }

        myPush('123')
        
    </script>
</body>

</html>